<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>state精简版（简写）</title>
</head>
<body>
  <div id="test"></div>

  <!-- 引入库：先引入核心库，再引入操作DOM的扩展库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <!-- 将jsx转为js -->
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/babel">    //必须写babel，因为默认js

    class Weather extends React.Component {
      /*
      constructor(props){
        super(props)
        // this.state = {isHot:true,wind:'微风'}   //这个可以直接放在类里面，如26行
        // this.changeWeather2 = this.changeWeather1.bind(this)    //34行，函数的简化方式
      }    */

      state = {isHot:true,wind:'微风'}


      render(){
        const {isHot,wind} = this.state
        return <h2 onClick={this.changeWeather}>今天天气很{isHot?'炎热':'凉爽'},{wind}</h2>
      }

      // 函数的简化
      // changeWeather1(){                //原本写法
      //   const isHot = this.state.isHot
      //   this.setState({isHot:!isHot})
      // }
      changeWeather = ()=>{                   //简写，要用赋值语句形式 + 箭头函数
        const isHot = this.state.isHot
        this.setState({isHot:!isHot})
      }
    }
    ReactDOM.render(<Weather/>, document.getElementById('test'))
  </script>
</body>
</html>